#!/bin/bash

# postinst script for system-boot-loader
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:sys $BASEDIR/boot
	chown root:sys $BASEDIR/boot/conf.d
	chown root:sys $BASEDIR/boot/defaults
	chown root:sys $BASEDIR/boot/forth
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/isoboot ] && rm -f $BASEDIR/boot/isoboot
	else
	    chmod 0444 "$BASEDIR/boot/isoboot"
	    chown root:bin "$BASEDIR/boot/isoboot"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/cdboot ] && rm -f $BASEDIR/boot/cdboot
	else
	    chmod 0444 "$BASEDIR/boot/cdboot"
	    chown root:sys "$BASEDIR/boot/cdboot"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/defaults/loader.conf ] && rm -f $BASEDIR/boot/defaults/loader.conf
	else
	    [ -f $BASEDIR/boot/defaults/loader.conf ] || cp -ax $BASEDIR/usr/share/doc/system-boot-loader/examples/loader.conf $BASEDIR/boot/defaults/loader.conf
	    chmod 0444 "$BASEDIR/boot/defaults/loader.conf"
	    chown root:sys "$BASEDIR/boot/defaults/loader.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/beadm.4th ] && rm -f $BASEDIR/boot/forth/beadm.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/beadm.4th"
	    chown root:sys "$BASEDIR/boot/forth/beadm.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/beastie.4th ] && rm -f $BASEDIR/boot/forth/beastie.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/beastie.4th"
	    chown root:sys "$BASEDIR/boot/forth/beastie.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/brand-dilos.4th ] && rm -f $BASEDIR/boot/forth/brand-dilos.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/brand-dilos.4th"
	    chown root:sys "$BASEDIR/boot/forth/brand-dilos.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/brand.4th ] && rm -f $BASEDIR/boot/forth/brand.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/brand.4th"
	    chown root:sys "$BASEDIR/boot/forth/brand.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/check-password.4th ] && rm -f $BASEDIR/boot/forth/check-password.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/check-password.4th"
	    chown root:sys "$BASEDIR/boot/forth/check-password.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/color.4th ] && rm -f $BASEDIR/boot/forth/color.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/color.4th"
	    chown root:sys "$BASEDIR/boot/forth/color.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/delay.4th ] && rm -f $BASEDIR/boot/forth/delay.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/delay.4th"
	    chown root:sys "$BASEDIR/boot/forth/delay.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/efi.4th ] && rm -f $BASEDIR/boot/forth/efi.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/efi.4th"
	    chown root:sys "$BASEDIR/boot/forth/efi.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/frames.4th ] && rm -f $BASEDIR/boot/forth/frames.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/frames.4th"
	    chown root:sys "$BASEDIR/boot/forth/frames.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/loader.4th ] && rm -f $BASEDIR/boot/forth/loader.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/loader.4th"
	    chown root:sys "$BASEDIR/boot/forth/loader.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/logo-beastie.4th ] && rm -f $BASEDIR/boot/forth/logo-beastie.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/logo-beastie.4th"
	    chown root:sys "$BASEDIR/boot/forth/logo-beastie.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/logo-beastiebw.4th ] && rm -f $BASEDIR/boot/forth/logo-beastiebw.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/logo-beastiebw.4th"
	    chown root:sys "$BASEDIR/boot/forth/logo-beastiebw.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/logo-fbsdbw.4th ] && rm -f $BASEDIR/boot/forth/logo-fbsdbw.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/logo-fbsdbw.4th"
	    chown root:sys "$BASEDIR/boot/forth/logo-fbsdbw.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/logo-orb.4th ] && rm -f $BASEDIR/boot/forth/logo-orb.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/logo-orb.4th"
	    chown root:sys "$BASEDIR/boot/forth/logo-orb.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/logo-orbbw.4th ] && rm -f $BASEDIR/boot/forth/logo-orbbw.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/logo-orbbw.4th"
	    chown root:sys "$BASEDIR/boot/forth/logo-orbbw.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/menu-commands.4th ] && rm -f $BASEDIR/boot/forth/menu-commands.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/menu-commands.4th"
	    chown root:sys "$BASEDIR/boot/forth/menu-commands.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/menu.4th ] && rm -f $BASEDIR/boot/forth/menu.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/menu.4th"
	    chown root:sys "$BASEDIR/boot/forth/menu.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/menu.rc ] && rm -f $BASEDIR/boot/forth/menu.rc
	else
	    [ -f $BASEDIR/boot/forth/menu.rc ] || cp -ax $BASEDIR/usr/share/doc/system-boot-loader/examples/menu.rc $BASEDIR/boot/forth/menu.rc
	    chmod 0444 "$BASEDIR/boot/forth/menu.rc"
	    chown root:sys "$BASEDIR/boot/forth/menu.rc"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/menusets.4th ] && rm -f $BASEDIR/boot/forth/menusets.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/menusets.4th"
	    chown root:sys "$BASEDIR/boot/forth/menusets.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/pcibios.4th ] && rm -f $BASEDIR/boot/forth/pcibios.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/pcibios.4th"
	    chown root:sys "$BASEDIR/boot/forth/pcibios.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/screen.4th ] && rm -f $BASEDIR/boot/forth/screen.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/screen.4th"
	    chown root:sys "$BASEDIR/boot/forth/screen.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/shortcuts.4th ] && rm -f $BASEDIR/boot/forth/shortcuts.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/shortcuts.4th"
	    chown root:sys "$BASEDIR/boot/forth/shortcuts.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/support.4th ] && rm -f $BASEDIR/boot/forth/support.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/support.4th"
	    chown root:sys "$BASEDIR/boot/forth/support.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/forth/version.4th ] && rm -f $BASEDIR/boot/forth/version.4th
	else
	    chmod 0444 "$BASEDIR/boot/forth/version.4th"
	    chown root:sys "$BASEDIR/boot/forth/version.4th"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/gptzfsboot ] && rm -f $BASEDIR/boot/gptzfsboot
	else
	    chmod 0444 "$BASEDIR/boot/gptzfsboot"
	    chown root:sys "$BASEDIR/boot/gptzfsboot"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/loader ] && rm -f $BASEDIR/boot/loader
	else
	    chmod 0444 "$BASEDIR/boot/loader"
	    chown root:sys "$BASEDIR/boot/loader"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/loader.help ] && rm -f $BASEDIR/boot/loader.help
	else
	    chmod 0444 "$BASEDIR/boot/loader.help"
	    chown root:sys "$BASEDIR/boot/loader.help"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/loader.rc ] && rm -f $BASEDIR/boot/loader.rc
	else
	    [ -f $BASEDIR/boot/loader.rc ] || cp -ax $BASEDIR/usr/share/doc/system-boot-loader/examples/loader.rc $BASEDIR/boot/loader.rc
	    chmod 0444 "$BASEDIR/boot/loader.rc"
	    chown root:sys "$BASEDIR/boot/loader.rc"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/pmbr ] && rm -f $BASEDIR/boot/pmbr
	else
	    chmod 0444 "$BASEDIR/boot/pmbr"
	    chown root:sys "$BASEDIR/boot/pmbr"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/pxeboot ] && rm -f $BASEDIR/boot/pxeboot
	else
	    chmod 0444 "$BASEDIR/boot/pxeboot"
	    chown root:sys "$BASEDIR/boot/pxeboot"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/loader32.efi ] && rm -f $BASEDIR/boot/loader32.efi
	else
	    chmod 0555 "$BASEDIR/boot/loader32.efi"
	    chown root:sys "$BASEDIR/boot/loader32.efi"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/boot/loader64.efi ] && rm -f $BASEDIR/boot/loader64.efi
	else
	    chmod 0555 "$BASEDIR/boot/loader64.efi"
	    chown root:sys "$BASEDIR/boot/loader64.efi"
	fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

